<?php

class Provider
{
	// Connect with adodb
	//----------------
	var $dns;
	var $server;
	var $user;
	var $pass;
	var $dbname;
	
	var $conn;
	var $connType;
	
	var $row;
	var $result;
	//----------------
	
	public function Provider()
	{
		$this->server = 'localhost';
		$this->user = 'root';
		$this->pass = '';
		$this->dns = "myData";
		$this->dbname = 'euf2';
		
		$this->connType = "mysql";
	}
	
	public function setConfig($ser, $uid, $pwd, $db)
	{
		$this->server = $ser;
		$this->user = $uid;
		$this->pass = $pwd;
		$this->dbname = $db;
	}
	
	public function openConnect()
	{
		switch ($this->connType)
		{
			case "mysql":
				$this->conn = mysql_connect ($this->server, $this->user, $this->pass) or die ('I cannot connect to the database because: ' . mysql_error());
				mysql_select_db ($this->dbname);
				mysql_query("SET NAMES 'utf8'", $this->conn);
				break;
			case "mssql":
				$this->conn = mssql_connect('MAY-3\SQLEXPRESS', 'sa', '1234') or die ('I cannot connect to the database because: ');
				mssql_select_db($this->dbname);
				//mssql_query("SET NAMES 'utf8'");
				break;
			case "odbc":
				$this->conn = odbc_connect($this->dns, $this->user, $this->pass) or die ('Cannot connect database ' . odbc_error());
				break;
		}
	}
	
	public function closeConnect()
	{
		switch ($this->connType)
		{
			case "mysql":
				mysql_close($this->conn);
				break;
			case "mssql":
				mssql_close($this->conn);
				break;
			case "odbc":
				odbc_close($this->conn);
				break;
		}
	}
	
	public function querySQL($sql)
	{
		switch ($this->connType)
		{
			case "mysql":
				$this->result = mysql_query($sql);
				break;
			case "mssql":
				$this->result = mssql_query($sql);
				break;
			case "odbc":
				$this->result = odbc_exec($this->conn, $sql);
				break;
		}
		return $this->result;
	}
	
	public function read()
	{
		switch ($this->connType)
		{
			case "mysql":
				$this->row = mysql_fetch_assoc($this->result);
				break;
			case "mssql":
				$this->row = mssql_fetch_array($this->result);
				break;
			case "odbc":
				$this->row = odbc_fetch_row($this->result);
				break;
		}
		return $this->row;
	}
	
	public function getValue($column)
	{
		$value;
		switch ($this->connType)
		{
			case "mysql":
				$value = $this->row[$column];
				break;
			case "mssql":
				$value = $this->row[$column];
				break;
			case "odbc":
				$value = odbc_result($this->result, $column);
				break;
		}
		return $value;
	}
}

?>